package ar.com.altaagenda.utils;

import org.htmlparser.Node;
import org.htmlparser.filters.StringFilter;
import org.htmlparser.tags.CompositeTag;

public class ElementAttributeFilter extends StringFilter {

	private static final long serialVersionUID = 1L;

	private Class<? extends CompositeTag> elementClass;
	
	public ElementAttributeFilter(Class<? extends CompositeTag> elementClass, String attribute, String value){
		super(attribute + "=\""+value+"\"");
		this.elementClass = elementClass;
	}
	
	public boolean accept (Node node){
        String string;
        boolean ret;

        ret = false;
        if (elementClass.isAssignableFrom(node.getClass())){
        	string = node.getText ();
	        if (!getCaseSensitive ()){
	        	string = string.toUpperCase (getLocale ());
	        }
	        ret = (-1 != string.indexOf (mUpperPattern));
	    }

	    return (ret);
    }
}
